import { BaseOpt } from "./base";
import { ContentModel } from "../models";

export default class ReplaceOpt extends BaseOpt{
  
  private index = 0
  private length = 0
  private data = ''
  private _deleted = ''
  
  constructor(index:number,length:number,data:string){
    super()
    this.index = index
    this.length = length
    this.data = data
    this.type = 'ReplaceOpt'
  }

  apply(): void {
    this._deleted = this._model.replace(this.index,this.length,this.data)
    if(this._selection){
      this._selection.update(this.index + this.data.length, 0)
    }
  }

  reverse(): void {
    this._model.replace(this.index,this.data.length,this._deleted)
    if(this._selection){
      this._selection.update(this.index + this._deleted.length, 0)
    }
  }

  merge(opt: BaseOpt): boolean {
    return false
  }
}